<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">资源分析</div>
        </div>
        <div class="widget-body  am-fr">
          <customer-toolbar ref="toolbar"  class="toolbar" @search="handleFind"  @export="handleExport"
                            areaTeam campusTeam alloCreateTime projectTime importOperatorName hasExport smallCategory bigCategory projectName resourceType department
          ></customer-toolbar>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              empty-text="暂无数据"
              stripe
              style="min-width: 100%">
              <el-table-column
                min-width="120"
                prop="areaTeamName"
                label="区域">
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="campusName"
                label="校区">
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="projectName"
                label="项目活动名称">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="projectTime"
                label="项目活动日期">
                <template scope="scope">
                  <div>{{scope.row.projectTime}}</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="bigCategory"
                label="来源大类">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="smallCategory"
                label="来源小类">
              </el-table-column>
              <el-table-column
                min-width="130"
                prop="studentAmount"
                label="分配资源数量">
              </el-table-column>
              <el-table-column
                min-width="140"
                prop="ontimeAmount"
                label="准时跟进数量">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="timeoutAmount"
                label="超时数量">
              </el-table-column>
              <el-table-column
                min-width="110"
                prop="notVisitAmount"
                label="未跟进数量">
              </el-table-column>
              <el-table-column
                min-width="110"
                prop="areaTeamName"
                label="及时跟进率">
                <template scope="scope">
                  <div>{{scope.row.ontimeAmount / scope.row.studentAmount * 100 | formatNumber(2)}}%</div>
                </template>
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="regStudentAmount"
                label="成交人数">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="regAmount"
                label="成交科数">
              </el-table-column>
              <el-table-column
                min-width="100"
                prop="totalAmount"
                label="成交金额">
              </el-table-column>
              <el-table-column
                min-width="170"
                fixed="right"
                prop="areaTeamName"
                label="成交学生占资源比例">
                <template scope="scope">
                  <div>{{scope.row.regStudentAmount / scope.row.studentAmount * 100 | formatNumber(2)}}%</div>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                        @paging="handlePage"/>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>
<script>
  import io from '../../lib/io'
  import CustomerToolbar from './CustomerToolbar.vue'
  import Pagination from '../base/Pagination.vue'
  import moment from 'moment'

  export default{
    data:function(){
      return {
        total: 0,
        pageSize: 10,
        pageNo: 1,
        tableData: [{}],
      }
    },
    components: {
      CustomerToolbar, Pagination
    },
    watch: {

    },
    computed: {

    },
    mounted :function(){
      $(window).smoothScroll()
//      this.loadTableData()
    },
    methods:{
      handleFind(formData) {
        this.formData = this.formatData(formData)
        this.pageNo = 1
        this.loadTableData()
      },
      handleExport(formData) {
        this.formData = this.formatData(formData)
        io.downloadFile(io.exportAnalyzeCustomerResource, this.formData, (ret) => {})
      },
      loadTableData: function () {
        this.$showLoading()
        io.post(io.analyzeCustomerResource, this.formData, (ret) => {
          this.$hiddenLoading()
          if (ret.success) {
            this.allData = ret.data
            this.total = ret.data.length
            this.handlePage()
          } else {
            this.$alert(ret.desc)
          }
        })
      },
      handlePage(pageNo) {
        this.pageNo = pageNo || this.pageNo || 1
        this.tableData = this.allData.slice((this.pageNo-1)*this.pageSize,this.pageSize*(this.pageNo))
      },
      formatData(data) {
        return {
          areaTeamId: data.areaTeamId,
          campusId: data.campusId,
          importOperatorName: data.importOperatorName,
          smallCategory: data.smallCategory,
          bigCategory: data.bigCategory,
          projectName: data.projectName,
          customerResourceType:data.customerResourceType,
          departmentId:data.departmentId,
          alloCreateTimeOfStart: data.alloCreateTime[0] ? moment(data.alloCreateTime[0]).format('YYYY-MM-DD') : '',
          alloCreateTimeOfEnd: data.alloCreateTime[1] ? moment(data.alloCreateTime[1]).format('YYYY-MM-DD') : '',
          projectTimeOfStart: data.projectTime[0] ? moment(data.projectTime[0]).format('YYYY-MM-DD') : '',
          projectTimeOfEnd: data.projectTime[1] ? moment(data.projectTime[1]).format('YYYY-MM-DD') : '',
        }
      }
    }
  }
</script>
<style lang="less" scoped>
</style>
